package com.qbccn.bbs.service.impl;

import com.qbccn.bbs.config.ValueConfig;
import com.qbccn.bbs.domain.BbsUserMenu;
import com.qbccn.bbs.mapper.BbsUserMenuMapper;
import com.qbccn.bbs.service.MenuService;
import com.qbccn.bbs.service.RedisService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author linke
 * @date 2020/7/31 22:17
 * @description
 */
@Service
public class MenuServiceImpl implements MenuService {

  @Autowired
  private BbsUserMenuMapper bbsUserMenuMapper;
  @Autowired
  private RedisService redisService;

  @Override
  public List<BbsUserMenu> getMenu(String username) {
    Object m = redisService.get("menu:" + username);
    if (m == null) {
      List<BbsUserMenu> menus = bbsUserMenuMapper.get(username);
      redisService.set("menu:" + username, menus, ValueConfig.redisUserMeunTime);
      return menus;
    }
    return (List<BbsUserMenu>) m;
  }
}
